import { Body, Controller, Post, UseGuards, Request } from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { AgentService } from './agent.service';
import { AgentExec } from './dto/agent.dto';
import { LoggerService } from '@/common/logger/logger.service';

@ApiBearerAuth()
@ApiTags('Agent')
@UseGuards(AuthGuard('jwt'))
@Controller({ path: 'agent', version: '1' })
export class AgentController {
  constructor(
    private service: AgentService,
    private logger: LoggerService,
  ) {}

  @Post('/exec')
  async exec(@Body() body: AgentExec, @Request() request) {
    const { content } = body;
    this.logger.debug({ ...request.use, content }, 'agent');
    return this.service.exec(request.user.sessionId, content);
  }
}
